/////////////////////////////////////////////////////////////////////////////
// Name:        dgt_mainframe.cpp
// Purpose:     
// Author:      Aleksey Plotnikov & Alla Nabatova
// Modified by: 
// Created:     19/03/2008 22:25:33
// RCS-ID:      
// Copyright:   Diamant Software
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dgt_mainframe.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "dgt_mainframe.h"
#include "dgt_StudioApp.h"
#include "dgt_StorePlugin.h"
#include "dgt_FileDialog.h"
#include "dgt_SyntezDialog.h"

////@begin XPM images
////@end XPM images
#include "Images/do.xpm"
#include "Images/if.xpm"
#include "Images/new_scheme.xpm"
#include "Images/beginend.xpm"
/*!
 * dgt_MainFrame type definition
 */

#include "dgt_ElementPlugin.h"
#include "dgt_Algorithm.h"
#include "sh_ptr.hpp"

IMPLEMENT_CLASS( dgt_MainFrame, wxFrame )


/*!
 * dgt_MainFrame event table definition
 */

BEGIN_EVENT_TABLE( dgt_MainFrame, wxFrame )

////@begin dgt_MainFrame event table entries
    EVT_MENU( ID_OPEN, dgt_MainFrame::OnOpenClick )

    EVT_MENU( ID_SAVE, dgt_MainFrame::OnSaveClick )

    EVT_MENU( ID_SAVEAS, dgt_MainFrame::OnSaveasClick )

    EVT_MENU( ID_SYNTEZ, dgt_MainFrame::OnSyntezClick )

    EVT_MENU( ID_TESTONLY, dgt_MainFrame::OnTestonlyClick )

    EVT_MENU( ID_TESTONLY2, dgt_MainFrame::OnTestonly2Click )

    EVT_MENU( ID_PLUGINDIALOG, dgt_MainFrame::OnPlugindialogClick )

    EVT_BUTTON( ID_BITMAPBUTTON1, dgt_MainFrame::OnDoButtonClick )

    EVT_BUTTON( ID_BITMAPBUTTON2, dgt_MainFrame::OnIfButtonClick )

    EVT_BUTTON( ID_BITMAPBUTTON3, dgt_MainFrame::OnBeginEndButtonClick )

////@end dgt_MainFrame event table entries

END_EVENT_TABLE()


/*!
 * dgt_MainFrame constructors
 */

dgt_MainFrame::dgt_MainFrame()
{
    Init();
}

dgt_MainFrame::dgt_MainFrame( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create( parent, id, caption, pos, size, style );
}


/*!
 * dgt_MainFrame creator
 */

bool dgt_MainFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin dgt_MainFrame creation
    wxFrame::Create( parent, id, caption, pos, size, style );

    this->SetBackgroundColour(wxColour(192, 192, 192));
    CreateControls();
    Centre();
////@end dgt_MainFrame creation
    return true;
}


/*!
 * dgt_MainFrame destructor
 */

dgt_MainFrame::~dgt_MainFrame()
{
////@begin dgt_MainFrame destruction
////@end dgt_MainFrame destruction
}


/*!
 * Member initialisation
 */

void dgt_MainFrame::Init()
{
////@begin dgt_MainFrame member initialisation
    m_Panel = NULL;
    m_Splitter = NULL;
    m_InputVars = NULL;
    m_IntrVars = NULL;
    m_OutputVars = NULL;
    m_SchemaPanel = NULL;
    m_AlgText = NULL;
    m_NewSchButton = NULL;
    m_DoButton = NULL;
    m_IfButton = NULL;
    m_BeginEndButton = NULL;
    m_DrawPanel = NULL;
////@end dgt_MainFrame member initialisation
}


/*!
 * Control creation for dgt_MainFrame
 */

void dgt_MainFrame::CreateControls()
{    
////@begin dgt_MainFrame content construction
    dgt_MainFrame* itemFrame1 = this;

    wxMenuBar* menuBar = new wxMenuBar;
    wxMenu* itemMenu3 = new wxMenu;
    itemMenu3->Append(ID_NEW, _("New..."), _T(""), wxITEM_NORMAL);
    itemMenu3->Append(ID_OPEN, _("Open..."), _T(""), wxITEM_NORMAL);
    itemMenu3->Append(ID_SAVE, _("Save"), _T(""), wxITEM_NORMAL);
    itemMenu3->Append(ID_SAVEAS, _("Save as..."), _T(""), wxITEM_NORMAL);
    itemMenu3->AppendSeparator();
    itemMenu3->Append(ID_SYNTEZ, _("Syntez"), _T(""), wxITEM_NORMAL);
    itemMenu3->AppendSeparator();
    itemMenu3->Append(ID_PRINT, _("Print..."), _T(""), wxITEM_NORMAL);
    itemMenu3->AppendSeparator();
    itemMenu3->Append(ID_EXIT, _("Exit"), _T(""), wxITEM_NORMAL);
    menuBar->Append(itemMenu3, _("Schema"));
    wxMenu* itemMenu14 = new wxMenu;
    itemMenu14->Append(ID_TESTONLY, _("Test only"), _T(""), wxITEM_NORMAL);
    itemMenu14->Append(ID_TESTONLY2, _("Test Only2"), _T(""), wxITEM_NORMAL);
    menuBar->Append(itemMenu14, _("Edit"));
    wxMenu* itemMenu17 = new wxMenu;
    itemMenu17->Append(ID_PLUGINDIALOG, _("Plugin dialog"), _T(""), wxITEM_NORMAL);
    menuBar->Append(itemMenu17, _("Plugins"));
    wxMenu* itemMenu19 = new wxMenu;
    menuBar->Append(itemMenu19, _("Help"));
    itemFrame1->SetMenuBar(menuBar);

    wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
    itemFrame1->SetSizer(itemBoxSizer20);

    wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer20->Add(itemBoxSizer21, 1, wxGROW, 5);

    wxAuiNotebook* itemAuiNotebook22 = new wxAuiNotebook( itemFrame1, ID_AUINOTEBOOK1, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON );

    m_Panel = new wxPanel( itemAuiNotebook22, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxHORIZONTAL);
    m_Panel->SetSizer(itemBoxSizer24);

    wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer24->Add(itemBoxSizer25, 1, wxGROW, 5);
    m_Splitter = new wxSplitterWindow( m_Panel, ID_SPLITTERWINDOW1, wxDefaultPosition, wxSize(100, 100), wxSP_3DBORDER|wxSP_3DSASH|wxNO_BORDER );
    m_Splitter->SetMinimumPaneSize(0);

    wxPanel* itemPanel27 = new wxPanel( m_Splitter, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer28 = new wxBoxSizer(wxHORIZONTAL);
    itemPanel27->SetSizer(itemBoxSizer28);

    wxBoxSizer* itemBoxSizer29 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer28->Add(itemBoxSizer29, 1, wxGROW, 5);
    wxStaticText* itemStaticText30 = new wxStaticText( itemPanel27, wxID_STATIC, _("Input variables list"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer29->Add(itemStaticText30, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    m_InputVars = new dgt_ListCtrl( itemPanel27, ID_INPUTVARS, wxDefaultPosition, wxSize(100, 250), wxLC_REPORT );
    itemBoxSizer29->Add(m_InputVars, 0, wxGROW, 5);

    wxStaticLine* itemStaticLine32 = new wxStaticLine( itemPanel27, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemBoxSizer29->Add(itemStaticLine32, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText33 = new wxStaticText( itemPanel27, wxID_STATIC, _("Internal variables list"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer29->Add(itemStaticText33, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    m_IntrVars = new dgt_ListCtrl( itemPanel27, ID_INTRVARS, wxDefaultPosition, wxSize(100, 250), wxLC_REPORT );
    itemBoxSizer29->Add(m_IntrVars, 0, wxGROW, 5);

    wxStaticLine* itemStaticLine35 = new wxStaticLine( itemPanel27, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemBoxSizer29->Add(itemStaticLine35, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText36 = new wxStaticText( itemPanel27, wxID_STATIC, _("Output variables list"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer29->Add(itemStaticText36, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    m_OutputVars = new dgt_ListCtrl( itemPanel27, ID_OUTVARS, wxDefaultPosition, wxSize(100, 250), wxLC_REPORT );
    itemBoxSizer29->Add(m_OutputVars, 0, wxGROW, 5);

    m_SchemaPanel = new wxPanel( m_Splitter, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer39 = new wxBoxSizer(wxVERTICAL);
    m_SchemaPanel->SetSizer(itemBoxSizer39);

    wxBoxSizer* itemBoxSizer40 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer39->Add(itemBoxSizer40, 1, wxGROW, 5);
    wxAuiNotebook* itemAuiNotebook41 = new wxAuiNotebook( m_SchemaPanel, ID_AUINOTEBOOK2, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );

    wxPanel* itemPanel42 = new wxPanel( itemAuiNotebook41, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer43 = new wxBoxSizer(wxHORIZONTAL);
    itemPanel42->SetSizer(itemBoxSizer43);

    wxBoxSizer* itemBoxSizer44 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer43->Add(itemBoxSizer44, 1, wxGROW, 5);
    m_AlgText = new wxTextCtrl( itemPanel42, ID_TEXTCTRL1, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    itemBoxSizer44->Add(m_AlgText, 1, wxGROW|wxALL, 5);

    itemAuiNotebook41->AddPage(itemPanel42, _("Text view"), false);

    wxPanel* itemPanel46 = new wxPanel( itemAuiNotebook41, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer47 = new wxBoxSizer(wxVERTICAL);
    itemPanel46->SetSizer(itemBoxSizer47);

    wxBoxSizer* itemBoxSizer48 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer47->Add(itemBoxSizer48, 0, wxGROW|wxALL, 5);
    m_NewSchButton = new wxBitmapButton( itemPanel46, ID_BITMAPBUTTON, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
    itemBoxSizer48->Add(m_NewSchButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticLine* itemStaticLine50 = new wxStaticLine( itemPanel46, wxID_STATIC, wxDefaultPosition, wxSize(1, 20), wxLI_VERTICAL );
    itemBoxSizer48->Add(itemStaticLine50, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_DoButton = new wxBitmapButton( itemPanel46, ID_BITMAPBUTTON1, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
    itemBoxSizer48->Add(m_DoButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_IfButton = new wxBitmapButton( itemPanel46, ID_BITMAPBUTTON2, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
    itemBoxSizer48->Add(m_IfButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_BeginEndButton = new wxBitmapButton( itemPanel46, ID_BITMAPBUTTON3, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
    itemBoxSizer48->Add(m_BeginEndButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer54 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer47->Add(itemBoxSizer54, 0, wxGROW, 5);
    wxStaticLine* itemStaticLine55 = new wxStaticLine( itemPanel46, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemBoxSizer54->Add(itemStaticLine55, 1, wxGROW, 5);

    wxBoxSizer* itemBoxSizer56 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer47->Add(itemBoxSizer56, 1, wxGROW|wxALL, 5);
    wxBoxSizer* itemBoxSizer57 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer56->Add(itemBoxSizer57, 1, wxGROW, 5);
    m_DrawPanel = new wxPanel( itemPanel46, ID_PANEL5, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    m_DrawPanel->SetBackgroundColour(wxColour(255, 255, 255));
    itemBoxSizer57->Add(m_DrawPanel, 1, wxGROW, 5);

    itemAuiNotebook41->AddPage(itemPanel46, _("Graphic view"), false);

    itemBoxSizer40->Add(itemAuiNotebook41, 1, wxGROW, 5);

    m_Splitter->SplitVertically(itemPanel27, m_SchemaPanel, 200);
    itemBoxSizer25->Add(m_Splitter, 1, wxGROW|wxALL, 5);

    itemAuiNotebook22->AddPage(m_Panel, _("Empty project"), false);

    itemBoxSizer21->Add(itemAuiNotebook22, 1, wxGROW|wxALL, 5);

////@end dgt_MainFrame content construction
	this->Maximize();

	m_Splitter->SetSashPosition( 260 );
	
	m_DoButton->SetBitmapLabel( wxBitmap( do_xpm) );
	m_IfButton->SetBitmapLabel( wxBitmap( if_xpm) );
	m_NewSchButton->SetBitmapLabel( wxBitmap( new_scheme_xpm) );
	m_BeginEndButton->SetBitmapLabel( wxBitmap( beginend_xpm) );

	m_InputVars->InsertColumn( 0, _T("Name"), wxLIST_FORMAT_LEFT, 50 );
	m_InputVars->InsertColumn( 1, _T("Library"), wxLIST_FORMAT_LEFT, 100 );
	m_InputVars->InsertColumn( 2, _T("Description"), wxLIST_FORMAT_LEFT, 120 );

	m_OutputVars->InsertColumn( 0, _T("Name"), wxLIST_FORMAT_LEFT, 50 );
	m_OutputVars->InsertColumn( 1, _T("Library"), wxLIST_FORMAT_LEFT, 100 );
	m_OutputVars->InsertColumn( 2, _T("Description"), wxLIST_FORMAT_LEFT, 120 );

	m_IntrVars->InsertColumn( 0, _T("Name"), wxLIST_FORMAT_LEFT, 50 );
	m_IntrVars->InsertColumn( 1, _T("Library"), wxLIST_FORMAT_LEFT, 100 );
	m_IntrVars->InsertColumn( 2, _T("Description"), wxLIST_FORMAT_LEFT, 120 );
}

/*!
 * Should we show tooltips?
 */

bool dgt_MainFrame::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap dgt_MainFrame::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin dgt_MainFrame bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end dgt_MainFrame bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon dgt_MainFrame::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin dgt_MainFrame icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end dgt_MainFrame icon retrieval
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DOBUTTON
 */

void dgt_MainFrame::OnDoButtonClick( wxCommandEvent& event )
{
 dgt_DoControl *do1 = new dgt_DoControl(m_DrawPanel, wxID_ANY, 
													   wxPoint(0,0), wxSize(140,50));
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_IFBUTTON
 */

void dgt_MainFrame::OnIfButtonClick( wxCommandEvent& event )
{
dgt_IfControl *ifcontrol = new dgt_IfControl(m_DrawPanel, wxID_ANY, 
													   wxPoint(0,0), wxSize(140,50));
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BEGINENDBUTTON
 */

void dgt_MainFrame::OnBeginEndButtonClick( wxCommandEvent& event )
{
dgt_BeginEndControl *becontrol = new dgt_BeginEndControl(m_DrawPanel, wxID_ANY, 
													   wxPoint(0,0), wxSize(140,50));
}


/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_PLUGINDIALOG
 */

void dgt_MainFrame::OnPlugindialogClick( wxCommandEvent& event )
{
	dgt_PluginManagerDlg* window = new dgt_PluginManagerDlg(this, ID_DGT_PLUGINMANAGERDLG, _("dgt_PluginManagerDlg"));
	window->MakeModal(true);
	window->Show(true);

}


/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TESTONLY
 */

////////////////////////////////// ONLY FOR TEST ///////////////////////////////////////////
void dgt_MainFrame::OnTestonlyClick( wxCommandEvent& event )
{
	dgt_AlgVarArray tInpVars;

	dgt_AlgVar_Ptr A( new dgt_AlgVar( _("A"), _("register.dll"), 0) );
	dgt_AlgVar_Ptr B( new dgt_AlgVar( _("B"), _("register.dll"), 0) );
	tInpVars.Add( A );
	tInpVars.Add( B );

	dgt_AlgVarArray tIntrVars;

	dgt_AlgVar_Ptr A1( new dgt_AlgVar( _("A1"), _("register.dll"), 0) );
	dgt_AlgVar_Ptr B1( new dgt_AlgVar( _("B1"), _("register.dll"), 0) );
	dgt_AlgVar_Ptr C1( new dgt_AlgVar( _("C"), _("register.dll"), 0) );
	tIntrVars.Add( A1 );
	tIntrVars.Add( B1 );
	tIntrVars.Add( C1 );

	dgt_AlgVarArray tOutVars;

	dgt_AlgVar_Ptr C( new dgt_AlgVar( _("C1"), _("register.dll"), 0) );
	tOutVars.Add( C );

	
	dgt_AlgCondArray tConds;
	wxArrayString tS;
	tS.Add( _("A(2,0)") );
	tS.Add( _("1"));
	dgt_AlgCondition_Ptr CO1( new dgt_AlgCondition( _("equal.dll"), 1, tS ) );
	tS.Clear();
	tS.Add( _("B(2,0)") );
	tS.Add( _("1"));
	dgt_AlgCondition_Ptr CO2( new dgt_AlgCondition( _("equal.dll"), 1, tS ) );
	tS.Clear();
	tS.Add( _("C(2,0)") );
	tS.Add( _("1"));
	dgt_AlgCondition_Ptr CO3( new dgt_AlgCondition( _("equal.dll"), 1, tS ) );
	tS.Clear();
	tConds.Add( CO1 );
	tConds.Add( CO2 );
	tConds.Add( CO3 );

	dgt_AlgActArray tActs;

	tS.Add( _("NOT(A)") );
	dgt_AlgAction_Ptr ACT1( new dgt_AlgAction( 1, _("A1"), 1, tS, false, wxEmptyString, 0 ));
	tS.Clear();
	tS.Add( _("A1") );
	tS.Add( _("1") );
	dgt_AlgAction_Ptr ACT2( new dgt_AlgAction( 2, _("A"), 1, tS, true, _("summator.dll"), 1 ));
	tS.Clear();
	tS.Add( _("NOT(B)") );
	dgt_AlgAction_Ptr ACT3( new dgt_AlgAction( 3, _("B1"), 1, tS, false, wxEmptyString, 0 ));
	tS.Clear();
	tS.Add( _("B1") );
	tS.Add( _("1") );
	dgt_AlgAction_Ptr ACT4( new dgt_AlgAction( 4, _("B"), 1, tS, true, _("summator.dll"), 1 ));
	tS.Clear();
	tS.Add( _("A") );
	tS.Add( _("B") );
	dgt_AlgAction_Ptr ACT5( new dgt_AlgAction( 5, _("C"), 1, tS, true, _("summator.dll"), 1 ));
	tS.Clear();
	tS.Add( _("NOT(C)") );
	dgt_AlgAction_Ptr ACT6( new dgt_AlgAction( 6, _("C1"), 1, tS, false, wxEmptyString, 0 ));
	tS.Clear();
	tS.Add( _("C1") );
	tS.Add( _("1") );
	dgt_AlgAction_Ptr ACT7( new dgt_AlgAction( 7, _("C"), 1, tS, true, _("summator.dll"), 1 ));
	tS.Clear();
	tS.Add( _("1") );
	tS.Add( _("1") );
	dgt_AlgAction_Ptr ACT8( new dgt_AlgAction( 8, _("C1"), 3, tS, false, wxEmptyString, 0 ));
	tS.Clear();
	tActs.Add( ACT1 );
	tActs.Add( ACT2 );
	tActs.Add( ACT3 );
	tActs.Add( ACT4 );
	tActs.Add( ACT5 );
	tActs.Add( ACT6 );
	tActs.Add( ACT7 );
	tActs.Add( ACT8 );

	dgt_AlgLogArray tLog;
	
	wxArrayInt tI;
	tI.Add( 1 );
	dgt_AlgLogic_Ptr LOG1( new dgt_AlgLogic( 0, 1, tI ) );
	tI.Clear();
	tI.Add( -1 );
	tI.Add( 2 );
	dgt_AlgLogic_Ptr LOG2( new dgt_AlgLogic( 0, 3, tI ) );
	tI.Clear();
	tI.Add( -1 );
	tI.Add( -2 );
	dgt_AlgLogic_Ptr LOG3( new dgt_AlgLogic( 0, 5, tI ) );
	tI.Clear();
	tI.Add( 0 );
	dgt_AlgLogic_Ptr LOG4( new dgt_AlgLogic( 1, 2, tI ) );
	tI.Clear();
	tI.Add( 2 );
	dgt_AlgLogic_Ptr LOG5( new dgt_AlgLogic( 2, 3, tI ) );
	tI.Clear();
	tI.Add( -2 );
	dgt_AlgLogic_Ptr LOG6( new dgt_AlgLogic( 2, 5, tI ) );
	tI.Clear();
	tI.Add( 0 );
	dgt_AlgLogic_Ptr LOG7( new dgt_AlgLogic( 3, 4, tI ) );
	tI.Clear();
	tI.Add( 0 );
	dgt_AlgLogic_Ptr LOG8( new dgt_AlgLogic( 4, 5, tI ) );
	tI.Clear();
	tI.Add( 3 );
	dgt_AlgLogic_Ptr LOG9( new dgt_AlgLogic( 5, 6, tI ) );
	tI.Clear();
	tI.Add( -3 );
	dgt_AlgLogic_Ptr LOG10( new dgt_AlgLogic( 5, -1, tI ) );
	tI.Clear();
	tI.Add( 0 );
	dgt_AlgLogic_Ptr LOG11( new dgt_AlgLogic( 6, 7, tI ) );
	tI.Clear();
	tI.Add( 0 );
	dgt_AlgLogic_Ptr LOG12( new dgt_AlgLogic( 7, 8, tI ) );
	tI.Clear();
	tI.Add( 0 );
	dgt_AlgLogic_Ptr LOG13( new dgt_AlgLogic( 8, -1, tI ) );
	tI.Clear();

	tLog.Add( LOG1 );
	tLog.Add( LOG2 );
	tLog.Add( LOG3 );
	tLog.Add( LOG4 );
	tLog.Add( LOG5 );
	tLog.Add( LOG6 );
	tLog.Add( LOG7 );
	tLog.Add( LOG8 );
	tLog.Add( LOG9 );
	tLog.Add( LOG10 );
	tLog.Add( LOG11 );
	tLog.Add( LOG12 );
	tLog.Add( LOG13 );

	dgt_Algorithm_Ptr pAlg( new dgt_Algorithm( _("TEST"), tActs, tConds, tLog, tInpVars, tIntrVars, tOutVars ));

	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();

	int x = pManager->get_PluginCount( PLUGIN_STORE );
	dgt_Plugin_Ptr plugin = pManager->get_Plugin( PLUGIN_STORE, 0 );

	plugin->SaveAlgorithm( pAlg, _("test.vdb") );

////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TESTONLY in dgt_MainFrame.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TESTONLY in dgt_MainFrame. */
}





/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TESTONLY2
 */

////////////////////////////////// ONLY FOR TEST ///////////////////////////////////////////
void dgt_MainFrame::OnTestonly2Click( wxCommandEvent& event )
{
/*	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();

	int x = pManager->get_PluginCount( PLUGIN_STORE );
	dgt_Plugin_Ptr plugin = pManager->get_Plugin( PLUGIN_STORE, 0 );

	dgt_Algorithm *t_Algorithm = plugin->LoadAlgorithm( _("test.vdb") );*/

////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TESTONLY2 in dgt_MainFrame.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TESTONLY2 in dgt_MainFrame. 
}


/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_OPEN
 */

void dgt_MainFrame::OnOpenClick( wxCommandEvent& event )
{
	dgt_FileDialog* pDialog = new dgt_FileDialog( this, true );
	if( pDialog->ShowModal() == wxID_OK ) 
	{
		dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
		dgt_PluginManager *pManager = tApp->get_Manager();

		int x = pManager->get_PluginCount( PLUGIN_STORE );
		dgt_Plugin_Ptr plugin = pManager->get_Plugin( PLUGIN_STORE, 0 );

		m_Alg = plugin->LoadAlgorithm( pDialog->get_DBName() );

		FillVariablesList();
		FillTextList();
	}
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_OPEN in dgt_MainFrame.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_OPEN in dgt_MainFrame. 
}


/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVE
 */

void dgt_MainFrame::OnSaveClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVE in dgt_MainFrame.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVE in dgt_MainFrame. 
}


/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVEAS
 */

void dgt_MainFrame::OnSaveasClick( wxCommandEvent& event )
{
	dgt_FileDialog* pDialog = new dgt_FileDialog( this, false );
	pDialog->ShowModal();

////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVEAS in dgt_MainFrame.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVEAS in dgt_MainFrame. 
}


/*!
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_SYNTEZ
 */

void dgt_MainFrame::OnSyntezClick( wxCommandEvent& event )
{
	dgt_SyntezDialog* pDialog = new dgt_SyntezDialog( this, false );
	if( pDialog->ShowModal() == wxID_OK )
	{
		dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
		dgt_PluginManager *pManager = tApp->get_Manager();

		unsigned PlugNum = pDialog->get_CAPlugCode();
		dgt_Plugin_Ptr tPlug = pManager->get_Plugin( PLUGIN_SYNTEZ_CA, PlugNum );

		unsigned oPlugNum = pDialog->get_OAPlugCode();
		dgt_Plugin_Ptr topPlug = pManager->get_Plugin( PLUGIN_SYNTEZ_OA, oPlugNum );

		unsigned TrigNum = pDialog->ger_TrigCode();
		dgt_Plugin_Ptr tTrigPlug = pManager->get_Plugin( PLUGIN_TRIGGER, PlugNum );
		dgt_Element_Ptr tElement = tTrigPlug->get_Element( 0 );

		tPlug->Synthesize( m_Alg, tElement );
		topPlug->Synthesize( m_Alg, tElement );

	}
	
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_SYNTEZ in dgt_MainFrame.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_SYNTEZ in dgt_MainFrame. 
}

void dgt_MainFrame::FillVariablesList()
{
	dgt_AlgVarArray tInpVars = m_Alg->get_InputVars();
	dgt_AlgVarArray	tIntrVars = m_Alg->get_InternalVars();
	dgt_AlgVarArray tOutVars = m_Alg->get_OutputVars();

	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();

	for( unsigned i = 0; i < tInpVars.Count(); i++ )
	{
		dgt_AlgVar_Ptr tItem = tInpVars.Item( i );
		m_InputVars->NewLine( NULL );
		m_InputVars->SetText( 0, tItem->get_Name() );
		m_InputVars->SetText( 1, tItem->get_PlugName() );

		dgt_Plugin_Ptr Plug = pManager->get_PluginByLibName( tItem->get_PlugName() );
		dgt_Element_Ptr tEl = Plug->get_Element( tItem->get_Code() );

		m_InputVars->SetText( 2, tEl->get_Name() );
	}

	for( unsigned i = 0; i < tIntrVars.Count(); i++ )
	{
		dgt_AlgVar_Ptr tItem = tIntrVars.Item( i );
		m_IntrVars->NewLine( NULL );
		m_IntrVars->SetText( 0, tItem->get_Name() );
		m_IntrVars->SetText( 1, tItem->get_PlugName() );

		dgt_Plugin_Ptr Plug = pManager->get_PluginByLibName( tItem->get_PlugName() );
		dgt_Element_Ptr tEl = Plug->get_Element( tItem->get_Code() );

		m_IntrVars->SetText( 2, tEl->get_Name() );
	}

	for( unsigned i = 0; i < tOutVars.Count(); i++ )
	{
		dgt_AlgVar_Ptr tItem = tOutVars.Item( i );
		m_OutputVars->NewLine( NULL );
		m_OutputVars->SetText( 0, tItem->get_Name() );
		m_OutputVars->SetText( 1, tItem->get_PlugName() );

		dgt_Plugin_Ptr Plug = pManager->get_PluginByLibName( tItem->get_PlugName() );
		dgt_Element_Ptr tEl = Plug->get_Element( tItem->get_Code() );

		m_OutputVars->SetText( 2, tEl->get_Name() );
	}
}

void	dgt_MainFrame::FillTextList( void )
{
	m_AlgText->AppendText( _("IF(A(2,0),1)\n"));
	m_AlgText->AppendText( _("{\n"));
	m_AlgText->AppendText( _("A1 = NOT(A)\n"));
	m_AlgText->AppendText( _("A = SUM(A1,1)\n"));
	m_AlgText->AppendText( _("}\n"));
	m_AlgText->AppendText( _("IF(B(2,0),1)\n"));
	m_AlgText->AppendText( _("{\n"));
	m_AlgText->AppendText( _("B1 = NOT(B)\n"));
	m_AlgText->AppendText( _("B = SUM(B1,1)\n"));
	m_AlgText->AppendText( _("}\n"));
	m_AlgText->AppendText( _("C = SUM(A,B)\n"));
	m_AlgText->AppendText( _("IF(C(2,0),1)\n"));
	m_AlgText->AppendText( _("{\n"));
	m_AlgText->AppendText( _("C1 = NOT(C)\n"));
	m_AlgText->AppendText( _("C = SUM(C1,1)\n"));
	m_AlgText->AppendText( _("}\n"));
}